package hasalah.demo.client;


import hasalah.demo.client.services.BackendService;
import hasalah.demo.client.services.BackendServiceAsync;
import hasalah.demo.client.views.DefaultPanel;
import hasalah.demo.client.views.EconomyConfigurationComposite;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class MVPDemo implements EntryPoint {

	private BackendServiceAsync backendServiceAsync = (BackendServiceAsync)GWT.create(BackendService.class);

	private RootPanel rootPanel;

	// GWT module entry point method.
	public void onModuleLoad() {
		/*
		 * Asynchronously loads the Maps API.
		 *
		 * The first parameter should be a valid Maps API Key to deploy this
		 * application on a public server, but a blank key will work for an
		 * application served from localhost.
		 */
		
		
		backendServiceAsync.saveEconomy(new AsyncCallback<String>() {
			
			@Override
			public void onSuccess(String result) {
				
				Window.alert(result);
				
			}
			
			@Override
			public void onFailure(Throwable caught) {
			
				
				Window.alert("Failed!!!");
				
	
				
			}
		});
		
		rootPanel = RootPanel.get();
		
	//	DockLayoutPanel p = new DockLayoutPanel(Unit.PX);
		
		
	//	p.addNorth(new HTML("Hasalah MVP"), 50);
		
	//    p.addSouth(new HTML("<small>2011</small>"), 100);
		
	//	p.addWest((Widget) getHyperLinks(), 50);
		
	//	DefaultPanel defaultPanel = new DefaultPanel(null);
		// defaultPanel.setBody(new ActivityFormComposite());
		
	//	p.add(defaultPanel.getMe());
		
	//	rootPanel.add(getHyperLinks());
		
		rootPanel.add(getHyperLinks());
		

	/*	
		Maps.loadMapsApi("", "2", false, new Runnable() {
			public void run() {
				buildUi();
			}
		});*/
	}

	@SuppressWarnings("deprecation")
	private IsWidget getHyperLinks() {

		Hyperlink economyLink = new Hyperlink("Define Economy","economy");
		
		economyLink.addClickHandler(new ClickHandler() {
			
			public void onClick(ClickEvent event) {

				DefaultPanel defaultPanel = new DefaultPanel("Econmony Configuration ..");
				
				defaultPanel.setBody(new EconomyConfigurationComposite());				
				
				defaultPanel.setWhereToGo("A", rootPanel);

				rootPanel.add(defaultPanel.getMe());
				
			}
		});
		
		VerticalPanel panel = new VerticalPanel();
		
		panel.add(economyLink);
		
		return panel;
		
	}
/*	@SuppressWarnings( "deprecation" )
	private IsWidget getHyperLinks() {

		Hyperlink economyLink = new Hyperlink("Define Economy","economy");
		
		economyLink.addClickHandler(new ClickHandler() {
			
			public void onClick(ClickEvent event) {

				DefaultPanel defaultPanel = new DefaultPanel("Econmony Configuration ..");
				
				defaultPanel.setBody(new EconomyConfigurationComposite());				
				
				
				rootPanel.add(defaultPanel.getMe());
				
			}
		});

		Hyperlink activityLink = new Hyperlink("Check-in Activity","checkin");
		
		activityLink.addClickHandler(new ClickHandler() {
			
			public void onClick(ClickEvent event) {

				DefaultPanel defaultPanel = new DefaultPanel("Check-in ..");
				
				defaultPanel.setBody(new CheckinActivityCompsite());				
				
				
				rootPanel.add(defaultPanel.getMe());
				
			}
		});

		Hyperlink levelLink = new Hyperlink("Conversion Activity ","conver");
		
		levelLink.addClickHandler(new ClickHandler() {
			
			public void onClick(ClickEvent event) {

				DefaultPanel defaultPanel = new DefaultPanel("Conversion ..");
				
				defaultPanel.setBody(new ConversionActivityCompsite());							
				
				rootPanel.add(defaultPanel.getMe());
				
			}
		});

		Hyperlink placeLink = new Hyperlink("Sharing Activity","share");
		
		placeLink.addClickHandler(new ClickHandler() {
			
			public void onClick(ClickEvent event) {

				DefaultPanel defaultPanel = new DefaultPanel("Sharing ..");
				
				defaultPanel.setBody(new SharingActivityCompsite());				
							
				rootPanel.add(defaultPanel.getMe());
				
			}
		});

		Hyperlink positionLink = new Hyperlink("SMS Activity","sms");
		
		positionLink.addClickHandler(new ClickHandler() {
			
			public void onClick(ClickEvent event) {

				DefaultPanel defaultPanel = new DefaultPanel("SMS ..");
				
				defaultPanel.setBody(new SMSActivityCompsite());				
							
				rootPanel.add(defaultPanel.getMe());
				
			}
		});

		Hyperlink rewardLink = new Hyperlink("Voting Activity","vote");
		
		rewardLink.addClickHandler(new ClickHandler() {
			
			public void onClick(ClickEvent event) {

				DefaultPanel defaultPanel = new DefaultPanel("Voting ..");
				
				defaultPanel.setBody(new VotingActivityComposite());				
								
				rootPanel.add(defaultPanel.getMe());
				
			}
		});

		
		VerticalPanel panel = new VerticalPanel();
		
		panel.add(economyLink);
		panel.add(activityLink);
		panel.add(levelLink);
		panel.add(placeLink);
		panel.add(positionLink);
		panel.add(rewardLink);
		
		return panel;
		
	}*/

}
